package com.pure.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pure.common.ClientSession;
import com.pure.common.ReturnData;
import com.pure.common.SysCodeMsg;
import com.pure.common.SystemConstant;
import com.pure.common.Util;
import com.pure.db.Business;
import com.pure.db.Develop;
import com.pure.db.Jobbusinessinfo;
import com.pure.db.User;
import com.pure.db.Userinfo;
import com.pure.db.Userjob;
import com.pure.service.UserService;

import oracle.net.aso.b;

@Controller
@RequestMapping("/ClientService")
public class ClientController extends BaseController {

	@Resource
	private UserService userService;

	@RequestMapping(params = "method=login", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData login(@RequestParam String loginname, @RequestParam String password, String source,
			@RequestParam String type) {
		ReturnData returnData = new ReturnData();
		try {
			if (loginname == "" || password == "") {
				returnData.setCode(SysCodeMsg.CODE_10003);
				returnData.setMessage(SysCodeMsg.MSG_10003);
				return returnData;
			}
			if (type.equals("0")) {
				User user = userService.getUserByLoginName(loginname, password);
				if (user == null || !user.getPassword().equals(password)) {
					returnData.setCode(SysCodeMsg.CODE_10004);
					returnData.setMessage(SysCodeMsg.MSG_10004);
					return returnData;
				}
				ClientSession client = new ClientSession();
				client.setLastTime(new Date().getTime());
				client.setUser(user);
				if (!Util.isNullString(source) && SystemConstant.MOBLE_MESSAGE.equals(source)) {
					client.setSource(source);
				}
				String token = (String) SystemConstant.token.get(loginname);
				if (Util.isNullString(token)) {
					// 生成唯一标识 UUID
					String uuid = UUID.randomUUID().toString();
					SystemConstant.token.put(loginname, uuid);
					SystemConstant.map.put(uuid, client);
					returnData.setData(user);
					returnData.setMessage(uuid);
					returnData.setCode("0");
					// return returnData;
				} else {
					// 生成唯一标识 UUID
					String uuid = UUID.randomUUID().toString();
					SystemConstant.map.remove(token);
					SystemConstant.token.put(loginname, uuid);
					SystemConstant.map.put(uuid, client);
					returnData.setData(user);
					returnData.setMessage(uuid);
					returnData.setCode("0");
					// return returnData;
				}
			} else if (type.equals("1")) {
				Business business = userService.getBusinessByLoginName(loginname, password);
				if (business == null || !business.getPassword().equals(password)) {
					returnData.setCode(SysCodeMsg.CODE_10004);
					returnData.setMessage(SysCodeMsg.MSG_10004);
					return returnData;
				}
				ClientSession client = new ClientSession();
				client.setLastTime(new Date().getTime());
				client.setBusiness(business);
				if (!Util.isNullString(source) && SystemConstant.MOBLE_MESSAGE.equals(source)) {
					client.setSource(source);
				}
				String token = (String) SystemConstant.token.get(loginname);
				if (Util.isNullString(token)) {
					// 生成唯一标识 UUID
					String uuid = UUID.randomUUID().toString();
					SystemConstant.token.put(loginname, uuid);
					SystemConstant.map.put(uuid, client);
					returnData.setData(business);
					returnData.setMessage(uuid);
					returnData.setCode("0");
					// return returnData;
				} else {
					// 生成唯一标识 UUID
					String uuid = UUID.randomUUID().toString();
					SystemConstant.map.remove(token);
					SystemConstant.token.put(loginname, uuid);
					SystemConstant.map.put(uuid, client);
					returnData.setData(business);
					returnData.setMessage(uuid);
					returnData.setCode("0");
					// return returnData;
				}
			} else if (type.equals("2")) {
				Develop develop = userService.getDevelopByLoginName(loginname, password);
				if (develop == null || !develop.getPassword().equals(password)) {
					returnData.setCode(SysCodeMsg.CODE_10004);
					returnData.setMessage(SysCodeMsg.CODE_10004);
					return returnData;
				}
				ClientSession client = new ClientSession();
				client.setLastTime(new Date().getTime());
				if (!Util.isNullString(source) && SystemConstant.MOBLE_MESSAGE.equals(source)) {
					client.setSource(source);
				}
				String token = (String) SystemConstant.token.get(loginname);
				if (Util.isNullString(token)) {
					// 生成唯一标识 UUID
					String uuid = UUID.randomUUID().toString();
					SystemConstant.token.put(loginname, uuid);
					SystemConstant.map.put(uuid, client);
					returnData.setMessage(uuid);
					returnData.setCode("0");
					// return returnData;
				} else {
					// 生成唯一标识 UUID
					String uuid = UUID.randomUUID().toString();
					SystemConstant.map.remove(token);
					SystemConstant.token.put(loginname, uuid);
					SystemConstant.map.put(uuid, client);
					returnData.setMessage(uuid);
					returnData.setCode("0");
					// return returnData;
				}
			}
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}

	@RequestMapping(params = "method=loginOut", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData loginOut(@RequestParam String uuid) {
		ReturnData returnData = new ReturnData();
		try {
			if (!Util.isNullString(uuid)) {
				// 注销移除uuid
				if (SystemConstant.map.keySet().contains(uuid)) {
					SystemConstant.map.remove(uuid);
					returnData.setData("注销成功.");
				} else {
					returnData.setData("此用户未登录或已经注销。");
				}
			}
			returnData.setCode("0");
			returnData.setMessage("success");
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}

	@RequestMapping(params = "method=addUser", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData addUser(@RequestParam String username, @RequestParam String password, @RequestParam String email,
			@RequestParam String name, @RequestParam String sex, @RequestParam String telphone,
			@RequestParam String studentid, @RequestParam String idcard, @RequestParam String phone,
			@RequestParam String type,@RequestParam String startTime,@RequestParam String endTime) {
		ReturnData returnData = new ReturnData();
		try {
			User user = new User();
			user.setEmail(email);
			user.setIdcard(idcard);
			user.setName(name);
			user.setPassword(password);
			user.setPhone(phone);
			user.setSex(sex);
			user.setStudentid(studentid);
			user.setTelphone(telphone);
			user.setUsername(username);
			user.setType(type);
			if (!Util.isNullString(startTime) && !Util.isNullString(endTime)) {
				SimpleDateFormat simpleDateFormat = new SimpleDateFormat(  
		                "yyyy-MM-dd HH:mm:ss");  
		        Date d1 = simpleDateFormat.parse(startTime);
				user.setStarttime(d1);
				
		        Date d2 = simpleDateFormat.parse(endTime);
				user.setEndtime(d2);
			}
			userService.addUser(user);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}

	@RequestMapping(params = "method=updateUser", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData updateUser(@RequestParam String username, @RequestParam String password,
			@RequestParam String email, @RequestParam String name, @RequestParam String sex,
			@RequestParam String telphone, @RequestParam String studentid, @RequestParam String idcard,
			@RequestParam String phone, @RequestParam String type, @RequestParam String uuid, @RequestParam String startTime,@RequestParam String endTime) {
		ReturnData returnData = new ReturnData();
		try {
			User user = new User();
			ClientSession client = (ClientSession) SystemConstant.map.get(uuid);
			user.setId(client.getUser().getId());
			user.setEmail(email);
			user.setIdcard(idcard);
			user.setName(name);
			user.setPassword(password);
			user.setPhone(phone);
			user.setSex(sex);
			user.setStudentid(studentid);
			user.setTelphone(telphone);
			user.setUsername(username);
			user.setType(type);
			if (!Util.isNullString(startTime) && !Util.isNullString(endTime)) {
				SimpleDateFormat simpleDateFormat = new SimpleDateFormat(  
		                "yyyy-MM-dd HH:mm:ss");  
		        Date d1 = simpleDateFormat.parse(startTime);
				user.setStarttime(d1);
				
		        Date d2 = simpleDateFormat.parse(endTime);
				user.setEndtime(d2);
			}
			
			userService.updateUser(user);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}
	@RequestMapping(params = "method=getUserById", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData getUserById(@RequestParam Integer id) {
		ReturnData returnData = new ReturnData();
		try {
			User user = userService.getUserById(id);
			returnData.setData(user);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}
		
	}

	@RequestMapping(params = "method=addUserInfo", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData addUserInfo(@RequestParam Integer age, @RequestParam String info, @RequestParam String major,
			@RequestParam String name, String sex, String telphone, String testresult, @RequestParam String uuid) {
		ReturnData returnData = new ReturnData();
		try {
			Userinfo userinfo = new Userinfo();
			ClientSession client = (ClientSession) SystemConstant.map.get(uuid);
			userinfo.setAge(age);
			userinfo.setInfo(info);
			userinfo.setMajor(major);
			userinfo.setName(name);
			userinfo.setSex(sex);
			userinfo.setTelphone(telphone);
			userinfo.setTestresult(testresult);
			userinfo.setUserid(client.getUser().getId());
			Integer count = userService.addUserInfo(userinfo);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}

	@RequestMapping(params = "method=updateUserInfo", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData updateUserInfo(@RequestParam Integer age, @RequestParam String info, @RequestParam String major,
			@RequestParam String name, String sex, String telphone, String testresult, @RequestParam String uuid,
			@RequestParam Integer id) {
		ReturnData returnData = new ReturnData();
		try {
			Userinfo userinfo = new Userinfo();
			userinfo.setAge(age);
			userinfo.setInfo(info);
			userinfo.setMajor(major);
			userinfo.setName(name);
			userinfo.setSex(sex);
			userinfo.setTelphone(telphone);
			userinfo.setTestresult(testresult);
			userinfo.setId(id);
			Integer count = userService.updateUserInfo(userinfo);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}

	@RequestMapping(params = "method=selectUserinfoById", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData selectUserinfoById(@RequestParam Integer id, @RequestParam String uuid) {
		ReturnData returnData = new ReturnData();
		try {

			Userinfo userinfo = userService.selectUserinfoById(id);
			returnData.setData(userinfo);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}
	@RequestMapping(params = "method=selectUserinfoByIdAndStatus", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData selectUserinfoByIdAndStatus(@RequestParam Integer id, @RequestParam String uuid) {
		ReturnData returnData = new ReturnData();
		try {
			
			Map<String, Object> userinfo = userService.selectUserinfoByIdAndStatus(id);
			returnData.setData(userinfo);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}
		
	}

	@RequestMapping(params = "method=selectUserinfo", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData selectUserinfo(@RequestParam String uuid) {
		ReturnData returnData = new ReturnData();
		try {
			ClientSession client = (ClientSession) SystemConstant.map.get(uuid);
			List<Userinfo> userinfos = userService.selectUserinfo(client.getUser().getId());
			returnData.setData(userinfos);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}

	@RequestMapping(params = "method=addBussiness", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData addBussiness(@RequestParam String email, @RequestParam String password,
			@RequestParam String regnum, @RequestParam String respname, String respphone, String contact,
			String username) {
		ReturnData returnData = new ReturnData();
		try {
			Business business = new Business();
			business.setEmail(email);
			business.setPassword(password);
			business.setRegnum(regnum);
			business.setRespname(respname);
			business.setRespphone(respphone);
			business.setContact(contact);
			business.setUsername(username);
			userService.addBussiness(business);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}
	@RequestMapping(params = "method=getBussinessById", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData getBussinessById(@RequestParam Integer id) {
		ReturnData returnData = new ReturnData();
		try {
			
			Business business = userService.getBussinessById(id);
			returnData.setData(business);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}
		
	}

	@RequestMapping(params = "method=updateBussiness", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData updateBussiness(@RequestParam String email, @RequestParam String password,
			@RequestParam String regnum, @RequestParam String respname, String respphone, String contact,
			String username, @RequestParam String uuid) {
		ReturnData returnData = new ReturnData();
		try {
			Business business = new Business();
			ClientSession client = (ClientSession) SystemConstant.map.get(uuid);
			business.setId(client.getBusiness().getId());
			business.setEmail(email);
			business.setPassword(password);
			business.setRegnum(regnum);
			business.setRespname(respname);
			business.setRespphone(respphone);
			business.setContact(contact);
			business.setUsername(username);
			userService.updateBussiness(business);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}

	@RequestMapping(params = "method=addBussinessInfo", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData addBussinessInfo(@RequestParam String description, @RequestParam Integer jobnum,
			@RequestParam String jobposition, @RequestParam Long salary, @RequestParam String telphone,
			@RequestParam String type, @RequestParam String uuid , @RequestParam String startTime, @RequestParam String endTime) {
		ReturnData returnData = new ReturnData();
		try {
			Jobbusinessinfo jobbusinessinfo = new Jobbusinessinfo();
			ClientSession client = (ClientSession) SystemConstant.map.get(uuid);
			jobbusinessinfo.setDescription(description);
			jobbusinessinfo.setBusinessid(client.getBusiness().getId());
			jobbusinessinfo.setJobnum(jobnum);
			jobbusinessinfo.setJobposition(jobposition);
			jobbusinessinfo.setSalary(salary);
			jobbusinessinfo.setTelphone(telphone);
			jobbusinessinfo.setType(type);
			if (!Util.isNullString(startTime) && !Util.isNullString(endTime)) {
				SimpleDateFormat simpleDateFormat = new SimpleDateFormat(  
		                "yyyy-MM-dd HH:mm:ss");  
		        Date d1 = simpleDateFormat.parse(startTime);
		        jobbusinessinfo.setStarttime(d1);
				
		        Date d2 = simpleDateFormat.parse(endTime);
		        jobbusinessinfo.setEndtime(d2);
			}
			userService.addBussinessInfo(jobbusinessinfo);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}

	@RequestMapping(params = "method=selectBussinessInfoById", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData selectBussinessInfoById(@RequestParam Integer id, @RequestParam String uuid) {
		ReturnData returnData = new ReturnData();
		try {

			Jobbusinessinfo jobbusinessinfo = userService.selectBussinessInfoById(id);
			returnData.setData(jobbusinessinfo);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}

	@RequestMapping(params = "method=selectBussinessInfo", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData selectBussinessInfoById(@RequestParam String uuid) {
		ReturnData returnData = new ReturnData();
		try {
			ClientSession client = (ClientSession) SystemConstant.map.get(uuid);
			List<Jobbusinessinfo> jobbusinessinfos = userService.selectBussinessInfo(client.getBusiness().getId());
			returnData.setData(jobbusinessinfos);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}

	@RequestMapping(params = "method=updateBussinessInfo", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData updateBussinessInfo(@RequestParam String description, @RequestParam Integer jobnum,
			@RequestParam String jobposition, @RequestParam Long salary, @RequestParam String telphone,
			@RequestParam String uuid, @RequestParam Integer id, @RequestParam String type, @RequestParam String startTime, @RequestParam String endTime) {
		ReturnData returnData = new ReturnData();
		try {
			Jobbusinessinfo jobbusinessinfo = new Jobbusinessinfo();
			jobbusinessinfo.setDescription(description);
			jobbusinessinfo.setId(id);
			jobbusinessinfo.setJobnum(jobnum);
			jobbusinessinfo.setJobposition(jobposition);
			jobbusinessinfo.setSalary(salary);
			jobbusinessinfo.setTelphone(telphone);
			jobbusinessinfo.setType(type);
			if (!Util.isNullString(startTime) && !Util.isNullString(endTime)) {
				SimpleDateFormat simpleDateFormat = new SimpleDateFormat(  
		                "yyyy-MM-dd HH:mm:ss");  
		        Date d1 = simpleDateFormat.parse(startTime);
		        jobbusinessinfo.setStarttime(d1);
				
		        Date d2 = simpleDateFormat.parse(endTime);
		        jobbusinessinfo.setEndtime(d2);
			}
			userService.updateBussinessInfo(jobbusinessinfo);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}

	@RequestMapping(params = "method=deleteBussinessInfo", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData deleteBussinessInfo(@RequestParam Integer id) {
		ReturnData returnData = new ReturnData();
		try {
			userService.deleteBussinessInfo(id);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}
	@RequestMapping(params = "method=deleteUserInfo", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData deleteUserInfo(@RequestParam Integer id) {
		ReturnData returnData = new ReturnData();
		try {
			userService.deleteUserInfo(id);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}
		
	}

	@RequestMapping(params = "method=getRecommendBussinessInfo", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData getRecommendBussinessInfo(@RequestParam String uuid) {
		ReturnData returnData = new ReturnData();
		try {

			ClientSession client = (ClientSession) SystemConstant.map.get(uuid);
			List<Jobbusinessinfo> jobbusinessinfos = userService.getAllBussinessInfo(client.getUser().getType());
			returnData.setData(jobbusinessinfos);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}

	}
	@RequestMapping(params = "method=getRecommendBussinessInfo1", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData getRecommendBussinessInfo1(@RequestParam String uuid) {
		ReturnData returnData = new ReturnData();
		try {
			
			ClientSession client = (ClientSession) SystemConstant.map.get(uuid);
			List<Jobbusinessinfo> jobbusinessinfos = userService.getAllBussinessInfo1(client.getUser().getStarttime(),client.getUser().getEndtime());
			returnData.setData(jobbusinessinfos);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}
		
	}
	@RequestMapping(params = "method=getAllBussinessInfo", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData getAllBussinessInfo(@RequestParam String uuid) {
		ReturnData returnData = new ReturnData();
		try {
			
			List<Jobbusinessinfo> jobbusinessinfos = userService.getAllBussinessInfo1();
			returnData.setData(jobbusinessinfos);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}
		
	}

	@RequestMapping(params = "method=applyBusiness", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData applyBusiness(@RequestParam String uuid, @RequestParam Integer jobbusinessinfoid,
			@RequestParam Integer userinfoid) {
		ReturnData returnData = new ReturnData();
		try {
			ClientSession client = (ClientSession) SystemConstant.map.get(uuid);
			boolean flag = userService.checkUse(client.getUser().getId());
			if (flag) {
				returnData.setCode(SysCodeMsg.CODE_20001);
				returnData.setMessage("已申请兼职！");
				return returnData;
			}
			Userjob userjob = new Userjob();
			userjob.setJobid(jobbusinessinfoid);
			userjob.setUserinfoid(userinfoid);
			userService.applyBusiness(userjob);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}
	}

	@RequestMapping(params = "method=applyStatusBusiness", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData applyStatusBusiness(@RequestParam String uuid, @RequestParam Integer status,
			@RequestParam Integer id) {
		ReturnData returnData = new ReturnData();
		try {
			
			Userjob userjob = new Userjob();
			userjob.setId(id);
			userjob.setStatus(status);
			userService.applyStatusBusiness(userjob);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}
	}
	@RequestMapping(params = "method=getUserjobById", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData getUserjobById(@RequestParam String uuid, @RequestParam Integer id) {
		ReturnData returnData = new ReturnData();
		try {
			
			Userjob userjob = userService.getUserjobById(id);
			returnData.setData(userjob);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}
	}
	@RequestMapping(params = "method=getApplyUserinfo", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData getApplyUserinfo(@RequestParam String uuid,@RequestParam Integer jobbusinessid,@RequestParam Integer status) {
		ReturnData returnData = new ReturnData();
		try {
			List<Map<String, Object>> userjob = userService.getApplyUserinfo(jobbusinessid,status);
			returnData.setData(userjob);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}
	}
	@RequestMapping(params = "method=getBussinessByjobid", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData getBussinessByjobid(@RequestParam String uuid,@RequestParam Integer jobid) {
		ReturnData returnData = new ReturnData();
		try {
			Business business = userService.getBussinessByjobid(jobid);
			returnData.setData(business);
			return returnData;
		} catch (Exception e) {
			returnData.setCode(SysCodeMsg.CODE_10000);
			returnData.setMessage(SysCodeMsg.MSG_10000);
			e.printStackTrace();
			return returnData;
		}
	}

}
